package cn.bearspark.api.controller.main;

import cn.bearspark.api.service.main.VoteService;
import cn.bearspark.api.vo.main.vote.VoteDetailVO;
import cn.bearspark.api.vo.main.vote.VoteReqVO;
import cn.bearspark.framework.web.starter.vo.ResponseVO;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 动态的投票模块
 *
 * @author f
 */
@Validated
@RestController
@RequestMapping("/vote")
public class VoteController {

    private final VoteService voteService;

    public VoteController(VoteService voteService) {
        this.voteService = voteService;
    }

    /**
     * 投票
     *
     * @param voteReqVO 投票的请求对象
     * @return 响应对象
     */
    @PostMapping("/vote")
    public ResponseVO<Object> vote(@Valid @RequestBody VoteReqVO voteReqVO) {
        return voteService.vote(voteReqVO);
    }

    /**
     * 查看投票详情
     *
     * @param voteId 投票的 id
     * @return 查看投票详情的响应对象
     */
    @GetMapping("/detail")
    public ResponseVO<VoteDetailVO> detail(@NotNull Long voteId) {
        return voteService.detail(voteId);
    }

}
